package com.example.mypotiota_si.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mypotiota_si.Datas.FenLie;
import com.example.mypotiota_si.R;

import java.util.ArrayList;

public class ListViewAdapter_fl extends RecyclerView.Adapter<ListViewAdapter_fl.ViewHolder> {
    ArrayList<FenLie> fenLie;

    public ListViewAdapter_fl(ArrayList<FenLie> fenLie) {
        this.fenLie = fenLie;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=View.inflate(parent.getContext(), R.layout.item_fl_list_view,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.setData(fenLie.get(position));
    }

    @Override
    public int getItemCount() {
        if (fenLie!=null){
            return fenLie.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView fl_name;
        private ImageView fl_icon;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            fl_name=itemView.findViewById(R.id.fl_name);
            fl_icon=itemView.findViewById(R.id.fl_icon);
        }


        public void setData(FenLie fenLie) {
            fl_name.setText(fenLie.fl_rice);
            fl_icon.setImageResource(fenLie.fl_icon);
        }
    }
}
